﻿//ReportViewer控件增加工具按钮

(function () {

    $.extend($.fn,

            {

                methods: {

                    createButton: function (width, height, type, uri, controlId) {

                        var A = $("<a></a>");

                        A.attr("id", type + "_" + "graph");

                        A.attr("href", "###");

                        A.attr("uri", uri);

                        A.css("margin-left", "5px");

                        var img = $("<img />");

                        img.attr("src", location.origin+"/Content/icons/" + type + ".png");

                        img.css("width", width);

                        img.css("height", height);

                        img.css("margin-top", "5px");

                        A.prepend(img);

                        A.click(function () {

                            $("input[id$='hid" + controlId + "']").val($(this).attr("uri"));

                            var lb = $("a[id$='lb" + controlId + "']");

                            //var a = parent.document.getElementById("mainiframe").contentWindow;
                            //a.focus();
                            //a.print();

                            //$find("ReportViewer1").prototype.PrintReport = function () {
                            //    this.PrintAs("Default");
                            //}

                            var viewerReference = $find("ReportViewer1");
                                var reportArea = viewerReference.get_reportAreaContentType();
                                if (reportArea == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
                                    $find("ReportViewer1").invokePrintDialog();
                                }

                            //__doPostBack(lb.attr("id").replace(/_/g, "$"), '');

                        });
                        A.hover(
                            function () {
                                $("#divRVT").css({ "font-family": "Verdana", "font-size": "8pt", "border": "1px solid rgb(51,102,153)", "background-color": "rgb(221,238,247)", "cursor": "default" });;
                            },
					        function () {
					            $("#divRVT").css({ "font-family": "Verdana", "font-size": "8pt", "border": "1px solid transparent", "background-color": "transparent", "cursor": "default" });;
					        });
                        return A;

                    }

                },

                ReportViewAddTool: function (options) {

                    $("#ReportViewer1_ctl05_ctl06_ctl00").hide();

                    options = $.extend({ width: 16, height: 16, url: { table: "###" }, controlId: "CallBack" }, options);

                    //按钮图片的宽度与高度

                    var width = options.width;

                    var height = options.height;

                    var url = options.url;

                    var controlId = options.controlId;


                    //创建图片按钮的div

                    var div = $("<div id='divRVT'></div>");

                    div.css({ "display": "inline", "font-family": "Verdana", "height": "30px", "width": "100%", "font-size": "8pt" });
                    $.each(url, function (k, v) {
                        div.prepend($.fn.methods.createButton(width, height, k, v, controlId));
                    });

                    $("#ReportViewer1_ctl05").children("div").append(div);

                }



            }

    );

})(jQuery);
